<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Marketing_fx extends MY_Controller {
	function __construct(){
	parent::__construct();
		$this->load->model('User_model');
		$this->smarty->assign("menu", "marketing");
		$parent_id = 9;
		//获取school二级菜单
		$this->load->model('School_manage_menu_model');
		$menu_list = $this->School_manage_menu_model->get_menu_list($this->is_manage,$parent_id);
			// print_r($menu_list);exit;
		$this->smarty->assign("menu_list", $menu_list);

		$this->left_menu_min = array("menu" => " 分销管理", "curr" => '/marketing_fx', "list" => $menu_list);
		$this->smarty->assign("left_menu_min", $this->left_menu_min);

		// $this->smarty->assign("menu", 'classes');

	}


	/**
	 * Index Page for this controller.
	 *
	 */
	public function index($status =-1,$limit = 0)
	{
		$post_data = $this->input->post();
		$st = 0;
		$et = 0;

		if($post_data){
			$st = !empty($post_data['st']) ? $post_data['st'] : 0;
			$et = !empty($post_data['et']) ? $post_data['et'] : 0;
		}

		$conditions['st'] = $st;
		$conditions['et'] = $et;
		$conditions['status'] = $status;
		$this->smarty->assign("data", $conditions);
		$this->smarty->assign("status", $status);

		//获取分销订单
		$this->load->model('Order_model');
		$order_list = $this->Order_model->get_fx_order_by_school($limit,15,$this->user_data['school_id'],$conditions);
		$this->smarty->assign("order_list", $order_list['result']);

		$this->load->library('pagination');
		$page_config['base_url'] = '/marketing_fx/index/'.$status;
		$page_config['total_rows'] = $order_list['total_count'];
		$page_config['per_page'] = 15;
		$page_config['uri_segment'] = 4;
		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();

		$this->smarty->assign("pagination", $pagination);

		//获取佣金总额
		$commission = $this->Order_model->get_commission($this->user_data['school_id'],$conditions);

		$this->smarty->assign("commission", $commission['commission']);
		$this->smarty->assign("order_amount", $commission['order_amount']);

		$this->smarty->display("marketing/marketing_fx.html");
	}

	public function share($limit=0)
	{
		//获取用户分享记录
		$this->load->model('User_share_model');
		$share_list = $this->User_share_model->get_share_by_school($this->user_data['school_id'],$limit,15);
		$this->smarty->assign("share_list", $share_list['result']);

		$this->load->library('pagination');
		$page_config['base_url'] = '/marketing_fx/share/';
		$page_config['total_rows'] = $share_list['total_count'];
		$page_config['per_page'] = 15;
		$page_config['uri_segment'] = 3;
		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();

		$this->smarty->assign("pagination", $pagination);
		$this->smarty->assign("menu", "marketing");
		$this->smarty->display("marketing/marketing_fx_share.html");
	}

	/**
	* 分销设置
	*/
	public function setting()
	{
		$this->load->model('Fenxiao_setting_model');

		$post_data = $this->input->post();
		if($post_data){
			if(empty($post_data['is_display_phone'])){
				$post_data['is_display_phone'] = 0;
			}

			$this->Fenxiao_setting_model->setting($this->user_data['school_id'],$post_data);
		}

		//获取设置
		$setting = $this->Fenxiao_setting_model->get_setting($this->user_data['school_id']);
		$this->smarty->assign("setting", $setting);

		$this->smarty->assign("menu", "marketing");
		$this->smarty->display("marketing/marketing_fx_setting.html");
	}

}
